package pers.acp.test.application.task

import com.fasterxml.jackson.dataformat.xml.XmlMapper
import io.gitee.zhangbinhub.acp.boot.job.AcpJob
import io.gitee.zhangbinhub.acp.boot.log.LogAdapter
import org.noear.snack4.ONode
import org.noear.solon.annotation.Component
import org.noear.solon.annotation.Inject
import org.noear.solon.core.handle.Context
import pers.acp.test.application.mapper.TableOneMapper
import pers.acp.test.application.mapper.TableTwoMapper

@Component(name = "testJob1")
class TestJob1(
    private val log: LogAdapter,
    private val xmlMapper: XmlMapper,
    @param:Inject private val tableOneMapper: TableOneMapper,
    @param:Inject private val tableTwoMapper: TableTwoMapper
) : AcpJob {
    @Inject(value = $$"${db_username:123}")
    private var dbUserName: String = ""
    override fun handle(ctx: Context) {
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>我是定时任务1》》》》》》》》》》")
        try {
            println("db username: $dbUserName")
            log.info("table 11 >>>>> \n" + ONode.serialize(tableOneMapper.selectAll()))
            log.info("table 12 >>>>> \n" + ONode.serialize(tableTwoMapper.selectAll()))
            log.info("table 11 >>>>> \n" + xmlMapper.writeValueAsString(tableOneMapper.selectAll()))
            log.info("table 12 >>>>> \n" + xmlMapper.writeValueAsString(tableTwoMapper.selectAll()))
        } catch (e: Exception) {
            log.error(e.message, e)
        }
    }
}